package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.EmployeeDTO;
import model.LeaveDTO;
import bizlogic.LeaveManager;
import bizlogic.User;

/**
 * Servlet implementation class SubordinateLeaveHisServlet
 */
@WebServlet("/SubordinateLeaveHisServlet")
public class SubordinateLeaveHisServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SubordinateLeaveHisServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	private void doprocess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try {
			User u = new User();
		
		HttpSession session = request.getSession(false);
		EmployeeDTO user = (EmployeeDTO) session.getAttribute("user");
		
		ArrayList<EmployeeDTO> employeelist = u.findByManager(user.getEmployeeID());
		LeaveManager lmgr = new LeaveManager();
		ArrayList<LeaveDTO> items = new ArrayList<LeaveDTO>();
		Iterator itr = employeelist.iterator();
		while( itr.hasNext())
		{
			LeaveDTO leave= lmgr.findLeave(user.getEmployeeID());
			items.add(leave);
			request.setAttribute("leaves", items);
			RequestDispatcher rd = request.getRequestDispatcher("SubordinateLeaveHistory.jsp");
			rd.forward(request, response);
		}	
			
		} 
		catch (ServletException e) {
			
			e.printStackTrace();
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}

}
